Skip to content

feat: restore legacy anchor alias to preserve old links#699

Merged
avivkeller merged 2 commits intonodejs:mainfrom
shivxmsharma:feat/restore-legacy-anchor-alias
Mar 27, 2026
Merged

feat: restore legacy anchor alias to preserve old links#699
avivkeller merged 2 commits intonodejs:mainfrom
shivxmsharma:feat/restore-legacy-anchor-alias

Conversation

@shivxmsharma
Copy link
Copy Markdown
Contributor

Fixes: #697

Description

Restores the legacy anchor alias for headings to preserve old documentation links.

The old Node.js doc generator (tools/doc/html.mjs) produced two anchor IDs per heading — a modern GitHub-style slug (e.g., #file-system) and a legacy underscore-based slug prefixed with the filename (e.g., #fs_file_system). External sites like Express and many others still link to these legacy anchors, and since doc-kit dropped them, those links silently break.

This PR ports the old getLegacyId algorithm into doc-kit and renders a hidden <a> element with the legacy ID alongside every heading, so both old and new anchor links resolve correctly.

Changes

  • src/generators/metadata/utils/slugger.mjs — Added getLegacySlug() function implementing the old underscore-based slug algorithm, and added a legacySlug() method to createNodeSlugger with counter-based deduplication.
  • src/generators/metadata/types.d.ts — Added legacySlug: string field to HeadingData interface.
  • src/generators/metadata/utils/parse.mjs — Generate legacySlug for every heading during metadata parsing.
  • src/generators/legacy-html/utils/buildContent.mjs — Render a hidden legacy anchor <a> element in the legacy HTML output.
  • src/generators/jsx-ast/utils/buildContent.mjs — Render a hidden legacy anchor <a> element in the JSX/AST (web) output.
  • src/generators/metadata/utils/__tests__/slugger.test.mjs — Added tests for getLegacySlug and createNodeSlugger.legacySlug.

Validation

  • All 349 existing tests pass (npm test).
  • Lint and formatting checks pass (npm run lint, npm run format:check).
  • Locally generated HTML output for a sample fs.md file confirms both anchors are present:
    • <a id=fs_file_system></a> (legacy) alongside <a class=mark id=file-system> (modern)
    • <a id=fs_fs_readfile_path></a> (legacy) alongside <a class=mark id=fsreadfilepath> (modern)

Related Issues

Fixes #697

Check List

  • I have read the Contributing Guidelines and made commit messages that follow the guideline.
  • I have run node --run test and all tests passed.
  • I have check code formatting with node --run format & node --run lint.
  • I've covered new added functionality with unit tests if necessary.

@shivxmsharma shivxmsharma requested a review from a team as a code owner March 23, 2026 08:48
@vercel
Copy link
Copy Markdown

vercel bot commented Mar 23, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
api-docs-tooling Ready Ready Preview Mar 27, 2026 11:25am

Request Review

@codecov
Copy link
Copy Markdown

codecov bot commented Mar 23, 2026

Codecov Report

❌ Patch coverage is 81.57895% with 14 lines in your changes missing coverage. Please review.
✅ Project coverage is 75.52%. Comparing base (d9697c7) to head (f4292a9).
⚠️ Report is 15 commits behind head on main.

Files with missing lines Patch % Lines
src/generators/legacy-html/utils/buildContent.mjs 0.00% 14 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #699      +/-   ##
==========================================
+ Coverage   75.44%   75.52%   +0.07%     
==========================================
  Files         148      150       +2     
  Lines       13572    13697     +125     
  Branches     1023     1041      +18     
==========================================
+ Hits        10239    10344     +105     
- Misses       3328     3348      +20     
  Partials        5        5              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copy link
Copy Markdown
Member

@avivkeller avivkeller left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any and all legacy slug generation should go in the legacy generator, not the metadata generator

@shivxmsharma
Copy link
Copy Markdown
Contributor Author

@avivkeller I've updated the PR to remove the legacy logic from the metadata/jsx-ast generators completely. All the legacy slug generation and its tests are now strictly isolated within the legacy-html generator as requested.

Let me know if there's anything else that needs adjusting!

@avivkeller
Copy link
Copy Markdown
Member

@shivxmsharma can you amend your commits to add me as a co author?

@shivxmsharma
Copy link
Copy Markdown
Contributor Author

@shivxmsharma can you amend your commits to add me as a co author?

Done! I've amended the commit to include you as a co-author.

@avivkeller avivkeller merged commit 584b0e9 into nodejs:main Mar 27, 2026
10 of 11 checks passed
@shivxmsharma shivxmsharma deleted the feat/restore-legacy-anchor-alias branch March 27, 2026 14:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Restore the anchor alias to preserve old links

2 participants